package com.pvdnc.systemdebugger.compacter;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.RemoteException;
import android.util.Log;

import com.pvdnc.systemdebugger.compacter.IAuth;

public class AuthProxy implements IAuth {
    private static final String TAG="AuthProxy";

    private IBinder mRemote;

    public AuthProxy(IBinder remote){
        this.mRemote=remote;
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            throw new RuntimeException();
        }
    };

    @Override
    public int request(String operation) {
        Parcel data=Parcel.obtain();
        data.writeString(operation);
        Parcel reply=Parcel.obtain();
        try {
            mRemote.transact(CODE_REQUEST,data,reply,0);
            int authResult=reply.readInt();
            Log.d(TAG,"auth result:"+authResult);
            return authResult;
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public IBinder asBinder() {
        return mRemote;
    }
}
